<template>
	<view>


		<view class="gui-bg-white gui-padding" v-if="currentIndex < 4">
			<gui-switch-navigation :items="navList" :currentIndex="currentIndex" @change="navchange" textAlign="center" :isCenter="true"
				activeDirection="center" :size="0" :margin="20" padding="30rpx"
				activeLineHeight="4rpx"></gui-switch-navigation>
		</view>
		
		<view class="gui-margin-top gui-padding-x gui-flex gui-row gui-wrap gui-space-between">
		
			<product-list-item v-for="item in products" :item="item">
			
			</product-list-item>
		</view>
		




	</view>
</template>

<script>
	import productListItem from "@/pages/product/product-list-item"
	export default {
		components: {
			productListItem
		},
		data() {
			return {
				navList: [{
					id: 0,
					name: '普通场'
				}, {
					id: 1,
					name: '清仓专场'
				}, {
					id: 2,
					name: '预售专场'
				}],
				currentIndex:0,
				products: []
			}
		},
		onLoad(e) {
			
			if(e.i){
				this.currentIndex= parseInt( e.i);
				if(this.currentIndex=='4'){
					uni.setNavigationBarTitle({
						title:"最热商机"
					})
				}
				if(this.currentIndex=='5'){
					uni.setNavigationBarTitle({
						title:"全部货源"
					})
				}
				if(this.currentIndex=='6'){
					uni.setNavigationBarTitle({
						title:"置顶货源"
					})
				}
				if(this.currentIndex=='7'){
					uni.setNavigationBarTitle({
						title:"普通货源"
					})
				}
				if(this.currentIndex=='9'){
					uni.setNavigationBarTitle({
						title:"我的收藏"
					})
				}
				if(this.currentIndex=='10'){
					uni.setNavigationBarTitle({
						title:"我的喜欢"
					})
				}
			}
			
			this.initData();
		},
		methods: {
			initData(){
				var self = this;
				
				var params = {};
				
				if(this.currentIndex == 1 || this.currentIndex==2||this.currentIndex==3||this.currentIndex==4){
					params.square_id= parseInt( this.currentIndex)+1;
					
				}
				if (this.currentIndex == 5 || this.currentIndex==6||this.currentIndex==7||this.currentIndex==9||this.currentIndex==10){
					var user = uni.gRequest.checkLogin();
					// console.log("是否登录",user)
					if(!user){
						return
					}
					params.user_id = user.user_id;
				}
			
				if(this.currentIndex==6){
					params.is_top= 1;
				}
				
				if(this.currentIndex == 7){
					params.square_id= 1;
				}
				if(this.currentIndex == 9){
					params.flag= 'shoucang';
				}
				if(this.currentIndex == 10){
					params.flag= 'xihuan';
				}
				
				
				
				
				
				
				uni.gRequest.get('product/list',params).then(result=>{
					 result.rows.forEach(x=>{
						 x.product_avater = uni.gRequest.server.replace('/app/','')+x.product_avater;
					 })
					
					self.products = result.rows;
				});
				
				
			},
			navchange: function(index) {
				this.currentIndex = index;
				this.initData();
			}
		}
	}
</script>

<style>

</style>